using System;
using System.Collections.Generic;

using EMan.BL.EntityEditing;
using EMan.BL.Properties;
using EMan.Common.EnterpriseStructure;
using EMan.Interface.Common;
using EMan.Interface.EnterpriseStructure.Employees;

using TrueCode.Core.Aspects;
using TrueCode.Core.Diagnostics;

namespace EMan.BL.EnterpriseStructure.Jobs
{
  [UsedImplicitly]
  public class JobChooserPresenter : EntityEditorPresenter, IJobChooserPresenter
  {
    #region Fields
    private readonly IEnterpriseStructure _eMan;
    private IEnumerable< Job > _jobs;

    private Job _selectedJob;
    #endregion

    #region .ctors
    public JobChooserPresenter( [NotNull] IEnterpriseStructure eMan, [NotNull] IDiagnostic diagnostic ) : base( diagnostic )
    {
      if( eMan == null ) throw new ArgumentNullException( "eMan" );

      _eMan = eMan;

      var executor = new ActivityExecutor( this, new Activity( Resources.Common_ActivityLoading_Title, null, true ) );
      executor.ExecuteAsync
      (
          _eMan.GetAllJobs,
          result => Jobs = result
      );
    }
    #endregion

    #region .dtor
    public override void Dispose()
    {
      
    }
    #endregion

    #region Implementation of IJobChooserPresenter
    public IEnumerable< Job > Jobs
    {
      get { return _jobs; }
      private set
      {
        _jobs = value;
        RaisePropertyChanged( () => Jobs );
      }
    }

    public Job SelectedJob
    {
      get { return Submited ? _selectedJob : null; }
      set { _selectedJob = value; }
    }
    #endregion
  }
}